package com.origin.onlinesys.service.modules.interviewsys.impl;

import com.origin.onlinesys.common.services.BaseService;
import com.origin.onlinesys.domain.modules.interviewsys.Department;
import com.origin.onlinesys.persistence.modules.interviewsys.DepartmentMapper;
import com.origin.onlinesys.service.modules.interviewsys.IDepartmentService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2015/2/10 0010.
 */
@Service
public class DepartmentServiceImpl extends BaseService<Department> implements IDepartmentService{
    /**
     * 添加部门
     * @param dept 部门对象
     * @return
     */
    public Department insertDept(Department  dept){
        String id = this.checkHave(dept.getName());
        dept.setState("1");
        if(id == null){
            dept.setId(this.save(dept)+"");
        }else{
            dept.setId(id);
            this.update(dept);
        }
        return dept;
    }

    /**
     * 删除部门
     * @param id
     * @return
     */
    public int deleteDept(String id){
        Department dept = new Department();
        dept.setId(id);
        dept.setState("2");
        return this.update(dept);
    }

    /**
     * 根据状态查询数据
     * @param state
     * @return
     */
    public List<Department> selectByState(String state){
        Department dept = new Department();
        dept.setState(state);
        return this.queryByWhere(dept);
    }

    public String checkHave(String name) {
        return ((DepartmentMapper)mapper).checkHave(name);
    }
}
